package com.example.springboot_shopsystem01.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.springboot_shopsystem01.domain.Staff;
import com.example.springboot_shopsystem01.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/staff")
public class StaffController {

    @Autowired
    private StaffService staffService;

    @GetMapping
    public List<Staff> getAll(){
        return staffService.getAll();
    }

    @PostMapping
    public Boolean save(@RequestBody Staff staff){  //通过请求体 传json数据过来
        return staffService.save(staff);
    }

    @PutMapping
    public Boolean update(@RequestBody Staff staff){
        return staffService.update(staff);
    }

    @DeleteMapping("{id}")   // 通过路径传参
    public boolean delete(@PathVariable Integer id){
        return staffService.delete(id);
    }

    @GetMapping("{id}")
    public Staff getById(@PathVariable Integer id){
        return staffService.getById(id);
    }

    @GetMapping("{currentPage}/{pageSize}")
    public IPage<Staff> getPage(@PathVariable int currentPage,@PathVariable int pageSize, Staff staff){
        return staffService.getPage(currentPage, pageSize, staff);
    }

    @PostMapping("/login")
    public Staff login(@RequestBody Staff s) {
        System.out.println(s);
        return staffService.login(s);
    }
}
